package com.ruoyi.factory.epros.controller.client;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.factory.epros.domain.DeptInfo;
import com.ruoyi.factory.epros.domain.PerByPost;
import com.ruoyi.factory.epros.domain.PersonInfo;
import com.ruoyi.factory.epros.domain.PostInfo;
import com.ruoyi.factory.epros.service.IEpDataSyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * @ClassName EpDataSynController
 * @Description: TODO epros业务处理类
 * @Author LiuJiaji
 * @Date 2023/2/10 10:46
 **/
@EnableScheduling
@Controller("epDataSynController")
public class EpDataSynController {

    @Autowired
    private IEpDataSyncService epDataSyncService;

    /**
     * @author: Liujiaji
     * @date: 2023/2/10 16:34
     * @description: TODO 同步epros数据
     * @param: []
     * @return: void
     **/
    public void toEpData(){
        perInfotoEpDa();
        deptInfotoEpDa();
        postInfotoEpDa();
        perByPosttoEpDa();
    }

    public void toEpData2(){
//        perByPosttoEpDaDe();
        perByPosttoEpDa();
//        deptInfotoEpDa();
//        postInfotoEpDa();
//        perByPosttoEpDa();
    }

    /**
     * @author: Liujiaji
     * @date: 2023/2/10 10:47
     * @description: TODO 同步erpos 人员数据
     * @param: []
     * @return: void
     **/
    public void perInfotoEpDa(){
        String perType = "1";
        //获取人员数据
        Map<String, List<PersonInfo>> perListMap = (Map<String, List<PersonInfo>>)epDataSyncService.personByOr(perType);
        //同步
        String pers = JSONObject.toJSONString(perListMap);
        epDataSyncService.toEpData(pers, perType);
    }

    /**
     * @author: Liujiaji
     * @date: 2023/2/10 16:27
     * @description: TODO 同步epros数据 部门数据
     * @param: []
     * @return: void
     **/
    public void deptInfotoEpDa(){
        String depType = "2";
        //获取部门数据
//        Map<String, List<DeptInfo>> depListMap = (Map<String, List<DeptInfo>>)epDataSyncService.personByOr(depType);
        //同步
//        String deps = JSONObject.toJSONString(depListMap);
        String deps = epDataSyncService.getDeptInfo();
        epDataSyncService.toEpData(deps,depType);
        //部门信息修改同步
        epDataSyncService.deptupdate();
    }

    public void postInfotoEpDa(){
        String depType = "3";
        //获取岗位数据
        Map<String, List<PostInfo>> depListMap = (Map<String, List<PostInfo>>)epDataSyncService.personByOr(depType);
        //同步
        String deps = JSONObject.toJSONString(depListMap);
        epDataSyncService.toEpData(deps,depType);
    }

    public void perByPosttoEpDa(){
        String depType = "4";
        //人员和岗位信息关联新增
        Map<String, List<PerByPost>> depListMap = (Map<String, List<PerByPost>>)epDataSyncService.personByOr(depType);
        //同步
        String deps = JSONObject.toJSONString(depListMap);
        epDataSyncService.toEpData(deps,depType);
    }

    public void perByPosttoEpDaDe(){
        String depType = "5";
        //人员和岗位信息关联删除
        Map<String, List<PerByPost>> depListMap = (Map<String, List<PerByPost>>)epDataSyncService.personByOr(depType);
        //同步
        String deps = JSONObject.toJSONString(depListMap);
        depType = "4";
        epDataSyncService.toEpData(deps,depType);
    }

}
